﻿package mortal.game.view.lotteryDraw
{
    import Message.DB.Tables.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.game.view.shopMall.view.*;
    import mortal.mvc.core.*;

    public class lotteryExchangeGoodsCellRender extends GCellRenderer
    {
        private var _shopItem:ShopSellItem;
        private var _xianjia:GTextFiled;
        private var _propName:GTextFiled;
        private var _price:GTextFiled;
        private var _buyBtn:GLoadingButton;
        private var _listPriceIcon:GBitmap;
        private var _numericStepper:GNumericStepper;
        private var _hasBuyIcon:GImageBitmap;

        public function lotteryExchangeGoodsCellRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:GTextFormat = null;
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.lotteryExchangeCellBg, 5, 4, this));
            _loc_1 = GlobalStyle.textFormatlan.right();
            this._price = UIFactory.gTextField("", 145 + 20, 40, 60, 25, this, _loc_1, true);
            _loc_1 = GlobalStyle.textFormatBai.center();
            this._listPriceIcon = UIFactory.gBitmap("", 205 + 20, 40, this);
            this._xianjia = UIFactory.gTextField(Language.getString(30061), 85 + 20, 40, 60, 25, this, _loc_1, true);
            _loc_1 = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._propName = UIFactory.gTextField("", 64 + 78, 12, 120, 25, this, _loc_1, true);
            this._shopItem = UICompomentPool.getUICompoment(ShopSellItem);
            this._shopItem.x = 30;
            this._shopItem.y = 24;
            this._shopItem.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this.addChild(this._shopItem);
            this._buyBtn = UIFactory.gLoadingButton(ResFileConst.ShopMallBuyBtn, 175 + 20, 70, 51, 24, this);
            this._buyBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            _loc_1.align = AlignMode.RIGHT;
            _loc_1.bold = false;
            this._numericStepper = UIFactory.gNumericStepper(100 + 20, 70, 50, 20, this, 99, 1, "NumericStepper", _loc_1);
            this._numericStepper.value = 1;
            return;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            super.selected = param1;
            if (selected)
            {
                EffectManager.glowFilterReg(this, null, 0.7, 5, 0);
            }
            else
            {
                EffectManager.glowFilterUnReg(this);
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_3:GTextFormat = null;
            super.data = param1;
            this._shopItem.isShowStreng = true;
            this._shopItem.shopItemData = param1.data as ShopItemData;
            this._shopItem.shopItemData.type = this._shopItem.shopItemData.tShopSell.isBindMoney;
            this._shopItem.amount = 1;
            var _loc_2:* = ShopConfig.instance.getTShopByCode(this._shopItem.shopItemData.tShopSell.shopCode) as TShop;
            this.setMoneyIcon(_loc_2.unit);
            this._numericStepper.value = 1;
            _loc_3 = GlobalStyle.textFormatBai.right();
            this._price.defaultTextFormat = _loc_3;
            this._xianjia.text = Language.getString(30061);
            this._price.text = this._shopItem.shopItemData.tShopSell.offer.toString();
            this._propName.htmlText = ItemsUtil.getItemName(this._shopItem.itemData);
            return;
        }// end function

        private function updateBuyRepet(param1:Object = null) : void
        {
            this.isHasItem = ShopUtil.isHasBuyItem(this._shopItem.itemData);
            return;
        }// end function

        private function setMoneyIcon(param1:int) : void
        {
            this._listPriceIcon.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(param1));
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            this._shopItem.shopItemData.num = this._numericStepper.value;
            Dispatcher.dispatchEvent(new DataEvent(EventName.BuyItem, this._shopItem));
            return;
        }// end function

        public function set isHasItem(param1:Boolean) : void
        {
            if (param1)
            {
                if (this._hasBuyIcon == null)
                {
                    this._hasBuyIcon = UIFactory.gImageBitmap(ImagesConst.ShopMallHasBuyIcon, 12 + 16, 40 - 10, this);
                }
            }
            else if (this._hasBuyIcon)
            {
                this._hasBuyIcon.dispose();
                this._hasBuyIcon = null;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._price.dispose(param1);
            this._shopItem.dispose(param1);
            this._buyBtn.dispose(param1);
            this._propName.dispose(param1);
            this._numericStepper.dispose(param1);
            this._xianjia.dispose(param1);
            this._price = null;
            this._shopItem = null;
            this._buyBtn = null;
            this._propName = null;
            this._numericStepper = null;
            this._xianjia = null;
            if (this._hasBuyIcon)
            {
                this._hasBuyIcon.dispose(param1);
                this._hasBuyIcon = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
